package com.ruoyi.project.system.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Anonymous;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.service.IDoctorRotaService;
import com.ruoyi.project.system.domain.vo.RotaDateVO;
import com.ruoyi.project.system.domain.vo.RotaPeriodVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 医生排班接口控制器（匹配前端 /dev-api/system/doctor/schedule 路径）
 */
@RestController
@RequestMapping("/system/doctor")
@Anonymous // 匿名访问（无需登录）
public class DoctorRotaController extends BaseController {

    @Autowired
    private IDoctorRotaService doctorRotaService;

    /**
     * 前端请求：GET /dev-api/system/doctor/schedule?doctorId={doctorId}&days=7
     * 根据医生ID查询近7天可预约日期
     */
    @GetMapping("/schedule")
    public AjaxResult get7DaysRota(@RequestParam("doctorId") String doctorId,
                                   @RequestParam(value = "days", required = false) Integer days) {
        // 前端传days=7，此处直接查询近7天（无需用days参数，按业务逻辑固定近7天）
        List<RotaDateVO> rotaDateVOList = doctorRotaService.get7DaysRota(doctorId);
        return AjaxResult.success(rotaDateVOList);
    }

    /**
     * 前端请求：GET /dev-api/system/doctor/schedule/period?doctorId={doctorId}&date={date}
     * 根据医生ID和日期查询当天可预约时段
     */
    @GetMapping("/schedule/period")
    public AjaxResult getRotaPeriod(@RequestParam("doctorId") String doctorId,
                                    @RequestParam("date") String date) {
        RotaPeriodVO periodVO = doctorRotaService.getRotaPeriod(doctorId, date);
        return AjaxResult.success(periodVO);
    }
}